﻿using System;

namespace Sustainalytics.ClientDW.Synchronization.Tests.IntegrationTests
{
    using Sustainalytics.Synchronization.Interface;
    using Sustainalytics.Utils;
    using System.Threading.Tasks;
    using Xunit;
    using Xunit.Abstractions;

    public class PDFGenerationSyncStepTests
    {
        private readonly ITestOutputHelper _output;

        private readonly ISyncStep _sut = new GeneratePdfReportSyncStep();

        public PDFGenerationSyncStepTests(ITestOutputHelper output)
        {
            this._output = output;
        }


        [Fact]
        public void StartPDFGeneration()
        {
            var context = TestSyncContextFactoy.Create();
            AggregateException exception = Assert.Throws<AggregateException>(() => this._sut.Start(context));
            this._output.WriteLine(context.Dump());
            foreach (var ex in exception.InnerExceptions)
            {
                this._output.WriteLine(ex.Message);
            }
        }
    }

    public class PdfClientTests

    {
        private readonly ITestOutputHelper _output;

        private readonly PDFGeneratorHttpClient _sut = new PDFGeneratorHttpClient("http://52.208.68.121/pdfgenerationserv/");
        public PdfClientTests(ITestOutputHelper output)
        {
            _output = output;
        }

        [Fact]
        public async Task StartPDFGeneration()
        {

            var exception = await Assert.ThrowsAsync<AggregateException>(
                async () => await this._sut.StartGenerationAsync(TestSyncContextFactoy.Create().GAConnectionStrings,false).ConfigureAwait(false)).ConfigureAwait(false);

            foreach (var ex in exception.InnerExceptions)
            {
                this._output.WriteLine(ex.Message);
            }
        }

        [Fact]
        public void CancelPDFGeneration()
        {

            var exception =
                Assert.ThrowsAsync<AggregateException>(
                    async () => await this._sut.CancelGenerationAsync().ConfigureAwait(false)).Result;

            foreach (var ex in exception.InnerExceptions)
            {
                this._output.WriteLine(ex.Message);
            }
        }
    }
}
